package four_File;

import java.io.*;

public class CopyBuffer {
    public static void main(String[] args) {
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        try {
            File fileIn = new File("mian\\src\\four_File\\from.txt");
            File fileOut = new File("mian\\src\\four_File\\to.txt");

            if (!fileOut.exists()) {
                try {
                    fileOut.createNewFile();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            bis = new BufferedInputStream(new FileInputStream(fileIn));
            bos = new BufferedOutputStream(new FileOutputStream(fileOut));


            int len;
            byte[] bys = new byte[1024];

            while ((len = bis.read(bys)) != -1) {
                bos.write(bys, 0, len);
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (bis != null) {
                try {
                    bis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (bos != null) {
                try {
                    bos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
